# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=presburger
pkgname=haskell-presburger
pkgver=1.3.1
pkgrel=21
pkgdesc="A decision procedure for quantifier-free linear arithmetic"
url="https://github.com/yav/presburger"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz"
        ghc-8.4.patch containers-0.6.patch ghc-8.8.patch)
sha512sums=('37659133b05452119b5bcb52111ceef41d4f54effe95f2c19164b807c3fcfb027aaf1c7f47d295ce9a2f57d1b8a5814a17e91f8814b3e963364bdcfb7aa5c1c0'
            'a063da967d7af8f339062188ef761d5df4b94937cc3a964263f8a174f6de4e0925e4f16225be0737bb9e1ab5f938e2f73867ec5b47c4e6c5117625b4c03788fa'
            '140390477480e951ccebd0d0e3d8cfb4b8cf08dad0f23bf26ca75e0bae8ca347f8e063a8ee63e770e2611ad831226767eed54963d43ed8c773c73d1fc72b56cc'
            '8a78409d14b1febfe496c7bb588d4cad6ff04ac41dcf76c2771ec4d6bb7192a5546c1b0f2e2c288d832d59120dba18413e57e17cf9af2fd52315623f06cb8682')

prepare() {
    cd $_hkgname-$pkgver
    patch -p1 -i ../ghc-8.4.patch
    patch -p1 -i ../containers-0.6.patch
    patch -p1 -i ../ghc-8.8.patch
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
